<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ref 回调函数使用形式</title>
    <style>
        #res{
            width: 400px;
            height: 300px;
            border:solid 1px #aaa;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        // element
        class App extends React.Component {
            render(){
                //返回虚拟 DOM 对象   input = document.createElement('input')
                return <div>
                        <h2>refs 的字符串使用形式</h2>
                        <input type="text"  ref={(el) => {
                            this.input = el
                        }} /> <button onClick={this.fasong} >发送</button>
                        <hr />
                        <div id="res" ref={el => this.res = el} ></div>
                    </div>
            }

            //声明方法
            fasong = () => {
                //获取 input 元素
                let input = this.input;
                let v = input.value;
                //获取 res 元素
                let res = this.res;
                //设置文本
                res.innerHTML = v;
            }
        }

        //渲染
        ReactDOM.render(<App />, document.querySelector('#root'));

    </script>
</body>
</html>